package com.atguigu.simple;

import java.beans.beancontext.BeanContext;
import java.util.Scanner;

/**
 * @ClassName 普通队列测试类
 * @DeScription TraditionQueue
 * @Author 剧情再美终是戏
 * @Date 2019/11/18 21:18
 * @Version 1.0
 **/
public class SimpleQueueTest {

    private static boolean flag = true;

    public static void main(String[] args) {
        SimpleQueue simpleQueue = new SimpleQueue(3);
        Scanner scanner = new Scanner(System.in);
        try {
            while (flag) {
                char cc;
                System.out.println("普通队列测试类");
                System.out.println("s(显示队列)");
                System.out.println("a(向队列添加数据)");
                System.out.println("g(向队列获取数据)");
                System.out.println("h(查询队列头部数据)");
                System.out.println("e(退出)");
                cc = scanner.next().charAt(0);

                switch (cc) {
                    case 's':
                        simpleQueue.show();
                        break;
                    case 'a':
                        System.out.println("请输入一个数字");
                        int n = scanner.nextInt();
                        simpleQueue.add(n);
                        break;
                    case 'g':
                        try {
                            System.out.printf("你取出的数据是%d\n", simpleQueue.get());
                        } catch (Exception e) {
                            System.out.println(e.getMessage());
                            continue;
                        }
                        break;
                    case 'h':
                        try {
                            simpleQueue.head();
                        } catch (Exception e) {
                            System.out.println(e.getMessage());
                            continue;
                        }
                        break;
                    case 'e':
                        flag = false;
                        scanner.close();
                        break;
                    default:
                        break;
                }
            }
            System.out.println("你已退出了~~~");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            scanner.close();
        }
    }
}

